import 'package:flutter/material.dart';
import 'package:gold/model/refund_model.dart';
import 'package:gold/utils/res.dart';
import 'package:gold/utils/xfg_color.dart';
import 'package:gold/utils/xfg_size.dart';
import 'package:gold/widgets/common_widgets.dart';
import 'package:gold/widgets/xfg_text.dart';

/// @description: 退款详情页面
/// @author tangzhentao
/// @created at 22:49 2025/2/27

class RefundDetailPage extends StatelessWidget {
  /// 金额 + 积分
  final String refund;
  /// 商品名称
  final List<RefundLogs> logs;

  const RefundDetailPage({super.key, required this.refund, required this.logs});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: xfgAppbar(title: '退款详情'),
      backgroundColor: XfgColor.white,
      body: SingleChildScrollView(
        padding: EdgeInsets.fromLTRB(XfgSize().size20, XfgSize().size60, XfgSize().size20, XfgSize().bottomBarHeight == 0 ? XfgSize().size10:XfgSize().bottomBarHeight),
        child: Column(
          children: [
            Image.asset(Res.imagesRefundDetail, width: XfgSize().size44, height: XfgSize().size44),
            Container(
              margin: EdgeInsets.only(top: XfgSize().size18),
              alignment: Alignment.center,
              child: XfgText('退款中$refund', fontSize: XfgSize().text20, color: XfgColor.text1D, bold: FontWeight.bold),
            ),
            Container(
              margin: EdgeInsets.only(top: XfgSize().size30, bottom: XfgSize().size26),
              padding: EdgeInsets.symmetric(horizontal: XfgSize().size24, vertical: XfgSize().size12),
              decoration: BoxDecoration(color: XfgColor.background, borderRadius: BorderRadius.circular(XfgSize().size6)),
              child: Column(
                children: [
                  _itemDetailWidget('实际退款金额', refund),
                  _itemDetailWidget('申请退款金额', refund),
                  _itemDetailWidget('预计到账时间', '预计0-3个工作日到账'),
                ],
              ),
            ),
            ...logs.map((log) {
              final index = logs.indexOf(log);
              final isFirst = index == 0;
              final isLast = index == logs.length - 1;
              return Column(
                children: [
                  Row(
                    children: [
                      Container(
                        width: XfgSize().size24,
                        padding: EdgeInsets.only(left: XfgSize().size2),
                        alignment: Alignment.centerLeft,
                        child: Container(
                          width: XfgSize().size5, height: XfgSize().size5,
                          decoration: BoxDecoration(color: isFirst ? XfgColor.refundApplyingCirce:XfgColor.colorB5, shape: BoxShape.circle),
                        ),
                      ),
                      Expanded(child: XfgText('支付宝正在处理您的退款', fontSize: XfgSize().text14, color: XfgColor.text1D, bold: FontWeight.bold))
                    ],
                  ),
                  SizedBox(height: XfgSize().size4),
                  IntrinsicHeight(
                    child: Row(
                      children: [
                        Container(
                          width: XfgSize().size5,
                          margin: EdgeInsets.only(left: XfgSize().size2, right: XfgSize().size17),
                          alignment: Alignment.center,
                          child: Visibility(
                            visible: !isLast,
                            child: Container(
                              width: XfgSize().size0_5,
                              color: XfgColor.text3,
                            ),
                          ),
                        ),
                        Expanded(child: Container(
                          padding: EdgeInsets.only(top: XfgSize().size4, bottom: XfgSize().size42),
                          alignment: Alignment.centerLeft,
                          child: XfgText('2024-12-23    12:12:23', fontSize: XfgSize().text14, color: XfgColor.text3),
                        ))
                      ],
                    ),
                  )
                ],
              );
            })
          ],
        ),
      )
    );
  }

  /// 退款信息通用Widget
  Widget _itemDetailWidget(String text, String value) => Padding(
    padding: EdgeInsets.symmetric(vertical: XfgSize().size12),
    child: Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        XfgText(text, fontSize: XfgSize().text14, color: XfgColor.text1D),
        XfgText(value, fontSize: XfgSize().text14, color: XfgColor.text1D),
      ],
    ),
  );
}
